Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / app / src / main / java / com / geeksville / mesh / ui / sharing / ChannelViewModel.kt

Displaying Raw • Download

app/src/main/java/com/geeksville/mesh/ui/sharing/ChannelViewModel.kt 78274c792318331b11ab64cd28e58e829875b8c2 (78274c79) Text, 4.65 KB

T8b949e/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

Tff7b72package T7ee787com.geeksville.mesh.ui.sharing

Tff7b72import T7ee787android.net.Uri
Tff7b72import T7ee787android.os.RemoteException
Tff7b72import T7ee787androidx.lifecycle.ViewModel
Tff7b72import T7ee787androidx.lifecycle.viewModelScope
Tff7b72import T7ee787dagger.hilt.android.lifecycle.HiltViewModel
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.meshtastic.core.analytics.DataPair
Tff7b72import T7ee787org.meshtastic.core.analytics.platform.PlatformAnalytics
Tff7b72import T7ee787org.meshtastic.core.data.repository.RadioConfigRepository
Tff7b72import T7ee787org.meshtastic.core.model.util.toChannelSet
Tff7b72import T7ee787org.meshtastic.core.service.ServiceRepository
Tff7b72import T7ee787org.meshtastic.core.ui.util.getChannelList
Tff7b72import T7ee787org.meshtastic.core.ui.viewmodel.stateInWhileSubscribed
Tff7b72import T7ee787org.meshtastic.proto.AppOnlyProtos
Tff7b72import T7ee787org.meshtastic.proto.ChannelProtos
Tff7b72import T7ee787org.meshtastic.proto.ConfigProtos.Config
Tff7b72import T7ee787org.meshtastic.proto.LocalOnlyProtos.LocalConfig
Tff7b72import T7ee787org.meshtastic.proto.channelSet
Tff7b72import T7ee787org.meshtastic.proto.config
Tff7b72import T7ee787org.meshtastic.proto.copy
Tff7b72import T7ee787timber.log.Timber
Tff7b72import T7ee787javax.inject.Inject

Tf0883e@HiltViewModel
Tff7b72class T56d364ChannelViewModel
Tf0883e@Inject
Tff7b72constructorTb4b4b4(
Tff7b72private Tff7b72val Te6edf3serviceRepositoryTb4b4b4: Te6edf3ServiceRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3radioConfigRepositoryTb4b4b4: Te6edf3RadioConfigRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3analyticsTb4b4b4: Te6edf3PlatformAnalyticsTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3ViewModelTb4b4b4(Tb4b4b4) Tb4b4b4{

Tff7b72val Te6edf3connectionState Tff7b72= Te6edf3serviceRepositoryTb4b4b4.Te6edf3connectionState

Tff7b72val Te6edf3localConfig Tff7b72=
Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3localConfigFlowTb4b4b4.Te6edf3stateInWhileSubscribedTb4b4b4(Te6edf3initialValue Tff7b72= Te6edf3LocalConfigTb4b4b4.Te6edf3getDefaultInstanceTb4b4b4(Tb4b4b4)Tb4b4b4)

Tff7b72val Te6edf3channels Tff7b72= Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3channelSetFlowTb4b4b4.Te6edf3stateInWhileSubscribedTb4b4b4(Te6edf3initialValue Tff7b72= Te6edf3channelSet Tb4b4b4{Tb4b4b4}Tb4b4b4)

T8b949e// managed mode disables all access to configuration
Tff7b72val Te6edf3isManagedTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3securityTb4b4b4.Te6edf3isManaged

Tff7b72var Te6edf3txEnabledTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3loraTb4b4b4.Te6edf3txEnabled
Tff7b72setTb4b4b4(Te6edf3valueTb4b4b4) Tb4b4b4{
Te6edf3updateLoraConfig Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copy Tb4b4b4{ Te6edf3txEnabled Tff7b72= Te6edf3value Tb4b4b4} Tb4b4b4}
Tb4b4b4}

Tff7b72var Te6edf3regionTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4.Te6edf3RegionCode
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3loraTb4b4b4.Te6edf3region
Tff7b72setTb4b4b4(Te6edf3valueTb4b4b4) Tb4b4b4{
Te6edf3updateLoraConfig Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copy Tb4b4b4{ Te6edf3region Tff7b72= Te6edf3value Tb4b4b4} Tb4b4b4}
Tb4b4b4}

Tff7b72private Tff7b72val Te6edf3_requestChannelSet Tff7b72= Te6edf3MutableStateFlowTff7b72<Te6edf3AppOnlyProtosTb4b4b4.Te6edf3ChannelSetTff7b72?Tff7b72>Tb4b4b4(Tff7b72nullTb4b4b4)
Tff7b72val Te6edf3requestChannelSetTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3AppOnlyProtosTb4b4b4.Te6edf3ChannelSetTff7b72?Tff7b72>
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3_requestChannelSet

Tff7b72fun Td2a8ffrequestChannelUrlTb4b4b4(Te6edf3urlTb4b4b4: Te6edf3UriTb4b4b4, Te6edf3onErrorTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tff7b72= Te6edf3runCatching Tb4b4b4{ Te6edf3_requestChannelSetTb4b4b4.Te6edf3value Tff7b72= Te6edf3urlTb4b4b4.Te6edf3toChannelSetTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3ex Tff7b72-Tff7b72>
Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffChannel url errorTa5d6ff"Tb4b4b4)
Te6edf3onErrorTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tff7b72fun Td2a8ffclearRequestChannelUrlTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3_requestChannelSetTb4b4b4.Te6edf3value Tff7b72= Tff7b72null
Tb4b4b4}

T8b949e/** Set the radio config (also updates our saved copy in preferences). */
Tff7b72fun Td2a8ffsetChannelsTb4b4b4(Te6edf3channelSetTb4b4b4: Te6edf3AppOnlyProtosTb4b4b4.Te6edf3ChannelSetTb4b4b4) Tff7b72= Te6edf3viewModelScopeTb4b4b4.Te6edf3launch Tb4b4b4{
Te6edf3getChannelListTb4b4b4(Te6edf3channelSetTb4b4b4.Te6edf3settingsListTb4b4b4, Te6edf3channelsTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3settingsListTb4b4b4)Tb4b4b4.Te6edf3forEachTb4b4b4(Tff7b72::Te6edf3setChannelTb4b4b4)
Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3replaceAllSettingsTb4b4b4(Te6edf3channelSetTb4b4b4.Te6edf3settingsListTb4b4b4)

Tff7b72val Te6edf3newConfig Tff7b72= Te6edf3config Tb4b4b4{ Te6edf3lora Tff7b72= Te6edf3channelSetTb4b4b4.Te6edf3loraConfig Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3lora Tff7b72!Tff7b72= Te6edf3newConfigTb4b4b4.Te6edf3loraTb4b4b4) Te6edf3setConfigTb4b4b4(Te6edf3newConfigTb4b4b4)
Tb4b4b4}

Tff7b72fun Td2a8ffsetChannelTb4b4b4(Te6edf3channelTb4b4b4: Te6edf3ChannelProtosTb4b4b4.Te6edf3ChannelTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3serviceRepositoryTb4b4b4.Te6edf3meshServiceTff7b72?.Te6edf3setChannelTb4b4b4(Te6edf3channelTb4b4b4.Te6edf3toByteArrayTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3RemoteExceptionTb4b4b4) Tb4b4b4{
Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffSet channel errorTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e// Set the radio config (also updates our saved copy in preferences)
Tff7b72fun Td2a8ffsetConfigTb4b4b4(Te6edf3configTb4b4b4: Te6edf3ConfigTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3serviceRepositoryTb4b4b4.Te6edf3meshServiceTff7b72?.Te6edf3setConfigTb4b4b4(Te6edf3configTb4b4b4.Te6edf3toByteArrayTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3RemoteExceptionTb4b4b4) Tb4b4b4{
Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffSet config errorTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tff7b72fun Td2a8fftrackShareTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3analyticsTb4b4b4.Te6edf3trackTb4b4b4(Ta5d6ff"Ta5d6ffshareTa5d6ff"Tb4b4b4, Te6edf3DataPairTb4b4b4(Ta5d6ff"Ta5d6ffcontent_typeTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffchannelTa5d6ff"Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72inline Tff7b72fun Td2a8ffupdateLoraConfigTb4b4b4(Te6edf3crossinline Te6edf3bodyTb4b4b4: Tb4b4b4(Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4) Tff7b72-Tff7b72> Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3data Tff7b72= Te6edf3bodyTb4b4b4(Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3loraTb4b4b4)
Te6edf3setConfigTb4b4b4(Te6edf3config Tb4b4b4{ Te6edf3lora Tff7b72= Te6edf3data Tb4b4b4}Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s